package com.myexam.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.myexam.model.Subject;
import com.myexam.service.SubjectService;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class SubjectAddAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1392952317038229841L;
	private String subjectTitle;
	private String subjectOptionA;
	private String subjectOptionB;
	private String subjectOptionC;
	private String subjectOptionD;
	private String subjectAnswer;
	private String subjectParse;
	
	@Autowired
	private SubjectService subjectService;

	public String getSubjectTitle() {
		return subjectTitle;
	}

	public void setSubjectTitle(String subjectTitle) {
		this.subjectTitle = subjectTitle;
	}

	public String getSubjectOptionA() {
		return subjectOptionA;
	}

	public void setSubjectOptionA(String subjectOptionA) {
		this.subjectOptionA = subjectOptionA;
	}

	public String getSubjectOptionB() {
		return subjectOptionB;
	}

	public void setSubjectOptionB(String subjectOptionB) {
		this.subjectOptionB = subjectOptionB;
	}

	public String getSubjectOptionC() {
		return subjectOptionC;
	}

	public void setSubjectOptionC(String subjectOptionC) {
		this.subjectOptionC = subjectOptionC;
	}

	public String getSubjectOptionD() {
		return subjectOptionD;
	}

	public void setSubjectOptionD(String subjectOptionD) {
		this.subjectOptionD = subjectOptionD;
	}

	public String getSubjectAnswer() {
		return subjectAnswer;
	}

	public void setSubjectAnswer(String subjectAnswer) {
		this.subjectAnswer = subjectAnswer;
	}

	public String getSubjectParse() {
		return subjectParse;
	}

	public void setSubjectParse(String subjectParse) {
		this.subjectParse = subjectParse;
	}

	public SubjectService getSubjectService() {
		return subjectService;
	}

	public void setSubjectService(SubjectService subjectService) {
		this.subjectService = subjectService;
	}
	
	public String execute() throws Exception{
		Subject subject = new Subject();
		//if(subjectAnswer.equals("") || subjectOptionA.equals("") || subjectOptionB.equals("")
		//		|| subjectOptionC.equals("") || subjectOptionD.equals("") || subjectTitle.equals("")){
		//	this.addActionError("重要选项不能为空！");
		//	return INPUT;
		//}else{
			subject.setSubjectTitle(subjectTitle);
			subject.setSubjectOptionA(subjectOptionA);
			subject.setSubjectOptionB(subjectOptionB);
			subject.setSubjectOptionC(subjectOptionC);
			subject.setSubjectOptionD(subjectOptionD);
			subject.setSubjectAnswer(subjectAnswer);
			subject.setSubjectParse(subjectParse);
			if(subjectService.saveSubjcet(subject)){
				return SUCCESS;
			}else{
				//addActionError("添加失败！");
				return INPUT;
			}
		//}
	}
}
